import router from '@/router'
import store from '@/store'
// 路由守卫.判断去的过程,未登录进行拦截
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  if (to.path === '/rent/add' ||
    to.path === '/rent' ||
    to.path === '/chat' ||
    to.path === '/favorite') return store.state.login.token ? next() : next('/login')
  next()
})
// 后置路由守卫
router.afterEach((to, from) => {
  // to and from are both route objects.
  // 如果当前的路由的元信息中，isRecord 的值为 true
  setTimeout(() => {
    window.scrollTo(0, to.meta.top)
  }, 0)
})
